{$CLEO .qa}
{$USE CLEO+}
{$USE newOpcodes}
{$USE ini}
{$USE Audio}

0000: NOP

script_name "GNGMUS"

// By ArtemQa146

const
    sound_wave = 31@
    gang_check = 29@
    sound_check = 30@
    sound_wave_wait = 28@
    sound_wave_riser = 27@
    sound_volume = 26@
end

gang_check = 7
sound_wave = -1
sound_check = 0

0AD3: 1@v = string_format "GNGSQ\%d_1.mp3" gang_check
0AAC: sound_wave = load_audio_stream 1@v
0AD3: 1@v = string_format "GNGSQ\%d_2.mp3" gang_check
0AAC: sound_wave_wait = load_audio_stream 1@v
0AAC: sound_wave_riser = load_audio_stream "GNGSQ\riser.mp3"
0AF2: sound_volume = read_float_from_ini_file "cleo\Improved Gangs War.ini" section "Gangs Ambient Sound" key "Volume"

repeat
wait 0
    0A8D: 1@  = read_memory 0x96AB64 size 1 virtual_protect 0 //  mov     eax, ds:_ZN9CGangWars5StateE ; CGangWars::State

    if
        1@ == 0
    then
        0AAD: set_audio_stream sound_wave_riser state 1
        0ABC: set_audio_stream sound_wave_riser volume sound_volume
        wait 1000
        if
            not sound_wave == -1
        then
            0AAE: remove_audio_stream sound_wave
        end
        if
            not sound_wave_wait == -1
        then
            0AAE: remove_audio_stream sound_wave_wait
        end
        
        wait 3000
        if
            not sound_wave_riser == -1
        then
            0AAE: remove_audio_stream sound_wave_riser
        end
        0A93: terminate_this_custom_script
    end
    
    if and
        1@ == 1
        sound_check == 0
    then
        0AAD: set_audio_stream sound_wave state 0
        gosub @Play_Music_wave
        sound_check = 1
        timera = 0
    end

    
    if and
        1@ == 2
        sound_check == 1
    then
        0AAD: set_audio_stream sound_wave_riser state 1
        0ABC: set_audio_stream sound_wave_riser volume sound_volume
        wait 1000
        0AAD: set_audio_stream sound_wave_wait state 0
        gosub @Play_Music
        sound_check = 2
    end
    
    if and
        1@ == 3
        sound_check == 2
    then
        0AAD: set_audio_stream sound_wave_riser state 1
        0ABC: set_audio_stream sound_wave_riser volume sound_volume
        wait 1000
        0AAD: set_audio_stream sound_wave state 0
        gosub @Play_Music_wave
        sound_check = 3
    end

    if and
        1@ == 4
        sound_check == 3
    then
        0AAD: set_audio_stream sound_wave_riser state 1
        0ABC: set_audio_stream sound_wave_riser volume sound_volume
        wait 1000
        0AAD: set_audio_stream sound_wave_wait state 0
        gosub @Play_Music
        sound_check = 4
    end
    
    if and
        1@ == 5
        sound_check == 4
    then
        0AAD: set_audio_stream sound_wave_riser state 1
        0ABC: set_audio_stream sound_wave_riser volume sound_volume
        wait 1000
        0AAD: set_audio_stream sound_wave state 0
        gosub @Play_Music_wave
        sound_check = 5
    end

    if and
        1@ == 6
        sound_check == 5
    then
        0AAD: set_audio_stream sound_wave_riser state 1
        0ABC: set_audio_stream sound_wave_riser volume sound_volume
        wait 1000
        0AAD: set_audio_stream sound_wave_wait state 0
        gosub @Play_Music
        sound_check = 6
    end
    
    if
        00DF:   actor $PLAYER_ACTOR driving
    then
        if
            not sound_wave == -1
        then
            0ABC: set_audio_stream sound_wave volume 0.0
        end
        if
            not sound_wave_wait == -1
        then
            0ABC: set_audio_stream sound_wave_wait volume 0.0
        end
    else
        if
            not sound_wave == -1
        then
            0ABC: set_audio_stream sound_wave volume sound_volume
        end
        if
            not sound_wave_wait == -1
        then
            0ABC: set_audio_stream sound_wave_wait volume sound_volume
        end
    end

until not player.Defined(0)
        if
            not sound_wave == -1
        then
            0AAE: remove_audio_stream sound_wave
        end
        if
            not sound_wave_wait == -1
        then
            0AAE: remove_audio_stream sound_wave_wait
        end
        if
            not sound_wave_riser == -1
        then
            0AAE: remove_audio_stream sound_wave_riser
        end

0A93: terminate_this_custom_script

:Play_Music
0AAD: set_audio_stream sound_wave state 1
0AC0: audio_stream sound_wave looped 1
0ABC: set_audio_stream sound_wave volume sound_volume
return

:Play_Music_wave
0AAD: set_audio_stream sound_wave_wait state 1
0AC0: audio_stream sound_wave_wait looped 1
0ABC: set_audio_stream sound_wave_wait volume sound_volume
return